package com.ia2014.tp.portal2.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.ia2014.tp.portal2.facades.FacadeIntegracion;
import com.ia2014.tp.portal2.vo.ArticuloVO;
import com.ia2014.tp.portal2.vo.ItemVentaVO;
import com.ia2014.tp.portal2.vo.VentaVO;
/**
 * Realiza de los objetos de portal para 
 * @author DiegoAlejandro
 *
 */
@WebServlet("/verArticulo")
public class VerArticuloServlet extends AbstractServlet {
	private static final long serialVersionUID = 1L;
	
	@EJB
	private FacadeIntegracion facade;

	public VerArticuloServlet(){
		super();
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		this.doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		this.comprobarSession(req, resp);
		this.process(req, resp);
	
	}	

	private void process(HttpServletRequest req, HttpServletResponse resp) 
			throws ServletException, IOException{
		
		HttpSession session = req.getSession(false);
		Integer idArticulo = Integer.parseInt(req.getParameter("idArticulo"));
		String  srcFunction = req.getParameter("srcFunction");
		if (srcFunction == null || srcFunction.trim().isEmpty()){
			srcFunction = "home";
		}		
	
		ArticuloVO articulo = this.facade.getArticuloById(idArticulo);
		
		session.setAttribute("articuloVO", articulo);
		session.setAttribute("srcFunction", srcFunction);
		
		resp.sendRedirect("articulo.jsp");
	}
}
